﻿#ifndef CHANNELITEMMODEL_H
#define CHANNELITEMMODEL_H

#include <QAbstractListModel>
#include <QStyledItemDelegate>

class BaseChannelInfo;
class ChannelInfo;
class P2PChanneInfo;

class ChannelItemModel : public QAbstractListModel
{
    Q_OBJECT
public:
    explicit ChannelItemModel(QObject *parent = Q_NULLPTR);

    void set_channel_list(QList<const BaseChannelInfo *> &const_channels);

    void add_channel(const BaseChannelInfo* channel);

    bool isChannelHidden(int row, const QString &keyword) const;

    void maybeReordered(const BaseChannelInfo *channel);
    void maybeReordered(const QList<const BaseChannelInfo*> &channels);
    void emitDataChanged(const BaseChannelInfo *channel);
    void emitDataChanged(const QList<const BaseChannelInfo*> &channels);

    int rowCount(const QModelIndex &parent) const Q_DECL_OVERRIDE;
    QModelIndex index(int row, int column, const QModelIndex &parent) const Q_DECL_OVERRIDE;
    QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
    Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
private:
    bool checkOrder(int row, const BaseChannelInfo *channel) const;
    QList<const BaseChannelInfo *> channel_list;
};

class ChannelItemDelegate : public QStyledItemDelegate
{
    Q_OBJECT
public:
    explicit ChannelItemDelegate(QObject *parent = Q_NULLPTR);
protected:
    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
private:
    void drawControl(const QStyleOptionViewItem *opt, QPainter *p, const QWidget *widget, const QPixmap &icon, const QModelIndex &index) const;
};

#endif // CHANNELITEMMODEL_H
